<template>
  <div class="block flex">
    <el-pagination
      :background="background"
      :page-sizes="pageSizes"
      :layout="layout"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange">
    </el-pagination>
  </div>
</template>


<script>
export default {
  name: 'Pagination',
  props: {
    background: {
      type: Boolean,
      default: true
    },
    pageSizes: {
      type: Array,
      default: () => {
        return [72,144,216,288]
      }
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    },
    total: {
      required: true,
      type: Number,
      default: 0
    },
    pageNum: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 10
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.pageNum
      },
      set(val) {
        this.$emit('update:pageNum', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.currentPage = 1;
      this.$emit('pagination', { pageNum: this.currentPage, limit: val })
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { pageNum: val, limit: this.pageSize })
    }
  }
}
</script>

<style scoped lang="scss">
.block{
  justify-content: center;
  padding: 20px;
  margin: 20px 0 0 0;
  font-weight: 400;
  color: #515a6e;
  ::v-deep.el-input__inner{
    height: 30px!important;
  }
  ::v-deep .el-pagination__total,::v-deep.el-pager li,::v-deep.btn-prev,::v-deep.btn-next{
    height: 30px;
    line-height: 30px;
  }
}
</style>
